﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EF4.IRepository;
using EF4.Model.Entities;
using EF4.Core.Repository;
using Microsoft.Practices.EnterpriseLibrary.Data;

using System.Data;
using System.Data.Common;

namespace EF4.Repository.SQL
{
    public class ProductRepository : GenericRepository<Product>, IProductRepository
    {
        IQueryable<Product> GetQuery()
        {
            throw new NotImplementedException();
        }

        Product Load(System.Linq.Expressions.Expression<Func<Product, bool>> whereCondition)
        {
            throw new NotImplementedException();
        }

        void LoadProperty(Product entity, System.Linq.Expressions.Expression<Func<Product, object>> selector)
        {
            throw new NotImplementedException();
        }

        List<Product> GetAll()
        {
            throw new NotImplementedException();
        }

        void Add(Product entity)
        {
            throw new NotImplementedException();
        }

        void Delete(Product entity)
        {
            throw new NotImplementedException();
        }

        void Update(Product entity)
        {
            throw new NotImplementedException();
        }
        public override Product Get(int id)
        {
            DbCommand dbCommand = database.GetStoredProcCommand("GetProductsById");
            try {
                
                database.AddInParameter(dbCommand, "ProductId", DbType.Int32, id);

                IDataReader reader = database.ExecuteReader(dbCommand);
                if (reader.Read())
                {
                    return ObjectBuilder.BuildProduct(reader);
                }
                
            }
            catch(Exception ex) {
                throw ex;
            }
            finally {
                dbCommand.Connection.Close();
            }
            return null;
        }
        

        Product Get(string KeyName, object value)
        {
            throw new NotImplementedException();
        }

        IPagedList<Product> GetListPaged(int pageIndex, int pageSize, string orderBy, Core.OrderDirections direction)
        {
            throw new NotImplementedException();
        }

        IPagedList<Product> GetListPaged(int pageIndex, int pageSize, string orderBy, Core.OrderDirections direction, System.Linq.Expressions.Expression<Func<Product, bool>> filter)
        {
            throw new NotImplementedException();
        }

        int Count()
        {
            throw new NotImplementedException();
        }

        void IDisposable.Dispose()
        {
            throw new NotImplementedException();
        }
    }
}
